<template>
    <div>
        <table class="table table-bordered" border="1">
            <tr>
                <td>用户名</td>
                <td><input type="text" v-model="info.yhm" /></td>
            </tr>

            <tr>
                <td>密码</td>
                <td>
                    <input type="text" v-model="info.pass" />
                </td>
            </tr>

            <tr>
                <td class="2"></td>
                <td><input type="button" value="登录" @click="add" /></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import { ref, onMounted } from 'vue'

const info = ref({
    yhm: '',
    pass: ''
})

const add = () => {
    if (info.value.yhm == '') {
        alert('用户名必须填写')
        return
    }
    if (info.value.pass == '') {
        alert('密码必须填写')
        return
    }

    axios
        .get('https://localhost:7190/api/User/login', {
            params: {
                yhm: info.value.yhm,
                pass: info.value.pass
            }
        })
        .then(res => {
            if (res.data > 0) {
                alert('登陆成功')
                location.href = 'Usershow'
            } else if (res.data == 0) {
                alert('登陆失败')
            } else if (res.data == -1) {
                alert('用户名不存在')
            }
        })
}
</script>

<style scoped></style>
